package mediatorPattern

class MarriageAgencyImpl : MarriageAgency {
    //男性会员
    private val man = ArrayList<Person>()

    //女性会员
    private val woman = ArrayList<Person>()


    override fun pair(person: Person) {
        when (person.sex) {
            Person.Sex.MALE -> {
                PrintUtil.print(person.toString())
                woman.forEach {
                    if (it.age in person.age - 5..person.age + 5) {
                        PrintUtil.print("已配对:")
                        PrintUtil.print(it.toString())
                    }
                }
            }
            Person.Sex.FEMALE -> {
                PrintUtil.print(person.toString())
                man.forEach {
                    if (it.age in person.age - 5..person.age + 5) {
                        PrintUtil.print("已配对:")
                        PrintUtil.print(it.toString())
                    }
                }
            }
        }
    }

    override fun register(person: Person) {
        when (person.sex) {
            Person.Sex.MALE -> man.add(person)
            Person.Sex.FEMALE -> woman.add(person)
        }
    }
}